<?php

namespace app\admin\controller\scanwork;

use app\common\controller\Api;
use app\common\model\TraceCode;
use think\Db;

/**
 * 追溯码API控制器
 */
class TraceApi extends Api
{
    protected $noNeedLogin = ['getTraceInfo'];
    protected $noNeedRight = ['*'];

    /**
     * 获取追溯信息
     */
    public function getTraceInfo()
    {
        $traceCode = $this->request->get('id');
        
        if (!$traceCode) {
            return json(['code' => 0, 'msg' => '追溯码不能为空']);
        }
        
        try {
            $traceInfo = TraceCode::getTraceInfo($traceCode);
            
            if (!$traceInfo) {
                return json(['code' => 0, 'msg' => '追溯码不存在或已失效']);
            }
            
            return json([
                'code' => 1,
                'msg' => '获取成功',
                'data' => $traceInfo
            ]);
            
        } catch (\Exception $e) {
            return json(['code' => 0, 'msg' => '获取追溯信息失败：' . $e->getMessage()]);
        }
    }
}
